// index_pkg/pages/delivery/index.js
Page({
  data: {
    activeNames: ['1'],
    fileList: [],
    fileList2: [],
    file:'',
    deletable: false,
    jobId:'',
    show:false
  },
  map(){
    wx.navigateTo({
      url: '/index_pkg/pages/map/index',
    })
  },
  cancel(){
    this.setData({show:false})
  },
  popup(){
    this.setData({show:!this.data.show})
  },
  onLoad(){
    this.getId()
  },
  defer(){
    wx.navigateTo({
      url: '/index_pkg/pages/defer/index',
    })
  },
  async getId(){
    const res =await wx.$http.get('/driver/tasks/details/' + jobId)
    console.log(res);
  },
  // 提货
  // async delivery (){
  //       const res = await wx.$http.post('/driver/tasks/takeDelivery')
  //       console.log(res);
  // },
  del(e){
      console.log(e.detail.index);
      this.data.fileList.splice(e.detail.index, 1);
      this.setData({fileList:this.data.fileList})
  },
  del2(e){
    this.data.fileList2.splice(e.detail.index, 1);
    this.setData({fileList2:this.data.fileList2})
  },
  goodsRead(e){
    console.log(e);
    const { file } = e.detail;
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      url:  wx.$http.baseURL + '/driver/files/imageUpload',
      filePath: file.url,
      name: 'file',
      formData: { user: 'test' },
      header: {
        Authorization:getApp().getToken()
      },
      success: (res) => {
        console.log(res)
        const { fileList2 = [] } = this.data;
        console.log(res.data);
        fileList2.push({ ...file, url: res.data.data});
        this.setData({ fileList2 });
      }
    });
  },
  afterRead(event) {
    const { file } = event.detail;
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      url:  wx.$http.baseURL + '/driver/files/upload',
      filePath: file.url,
      name: 'file',
      formData: { user: 'test' },
      header: {
        Authorization:getApp().getToken()
      },
      success: (res) => {
        console.log(res)
        const { fileList = [] } = this.data;
        fileList.push({ ...file, url: res.data});
        this.setData({ fileList });
      }
    });
  },
  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },
  /**
   * 页面的初始数据
   */
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})